Skip to content

fix(profiling): Reset shouldStop flag on startProfiler#5284

Open
43jay wants to merge 1 commit intomainfrom
fix/profiling-shouldstop-reset
Open

fix(profiling): Reset shouldStop flag on startProfiler#5284
43jay wants to merge 1 commit intomainfrom
fix/profiling-shouldstop-reset

Conversation

@43jay
Copy link
Copy Markdown
Collaborator

@43jay 43jay commented Apr 10, 2026

📜 Description

shouldStop is never reset to false after stopProfiler(), so a stop/start cycle leaves shouldStop=true. When the next 60-second chunk timer fires, stop(restartProfiler=true) checks !shouldStop and does not restart — the profiler silently stops after one chunk instead of continuing indefinitely.

This affects both lifecycle modes:

  • MANUAL: Sentry.startProfiler()Sentry.stopProfiler()Sentry.startProfiler() — second session stops after one chunk
  • TRACE: all transactions finish (rootSpanCounter reaches 0, sets shouldStop=true) → new transaction starts → profiler starts but stops after one chunk

Fix: reset shouldStop = false at the top of startProfiler(), since it represents a new intent to profile.

💡 Motivation and Context

Discovered while working on the Perfetto ProfilingManager integration (#5251). The same bug existed in both AndroidContinuousProfiler and PerfettoContinuousProfiler.

💚 How did you test it?

Unit test added: manual profiler can be started again after a full start-stop cycle — starts profiling, stops it, starts again, verifies the profiler continues running after the first chunk restart.

JAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :sentry-android-core:testDebugUnitTest --tests "io.sentry.android.core.AndroidContinuousProfilerTest.manual profiler can be started again after a full start-stop cycle"

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

None — standalone bugfix.

…artProfiler

Same fix as PerfettoContinuousProfiler — shouldStop was never reset to
false after stopProfiler, so a stop/start cycle would leave
shouldStop=true and silently stop the profiler after one chunk.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • (profiling) Reset shouldStop flag on startProfiler by 43jay in #5284

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Fixes

- Reset shouldStop flag on startProfiler ([#5284](https://github.com/getsentry/sentry-java/pull/5284))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against a9847ae

@43jay 43jay marked this pull request as ready for review April 10, 2026 16:24
@sentry
Copy link
Copy Markdown

sentry bot commented Apr 10, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
SDK Size io.sentry.tests.size 8.38.0 (1) release Install Build

Configure sentry-android build distribution settings

@github-actions
Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 359.43 ms 434.58 ms 75.15 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
889ecea 367.58 ms 437.52 ms 69.94 ms
d15471f 343.13 ms 361.47 ms 18.34 ms
9fbb112 404.51 ms 475.65 ms 71.14 ms
9ea89e8 308.06 ms 358.16 ms 50.10 ms
ee747ae 415.92 ms 470.15 ms 54.23 ms
ee747ae 405.43 ms 485.70 ms 80.28 ms
a416a65 316.52 ms 359.67 ms 43.15 ms
b193867 331.08 ms 397.06 ms 65.98 ms
91bb874 310.68 ms 359.24 ms 48.56 ms
6405ec5 310.88 ms 354.56 ms 43.69 ms

App size

Revision Plain With Sentry Diff
889ecea 1.58 MiB 2.11 MiB 539.75 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
9fbb112 1.58 MiB 2.11 MiB 539.18 KiB
9ea89e8 1.58 MiB 2.28 MiB 716.23 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
a416a65 1.58 MiB 2.12 MiB 555.26 KiB
b193867 1.58 MiB 2.19 MiB 620.00 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
6405ec5 1.58 MiB 2.12 MiB 552.23 KiB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant